package demo523;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Scanner;

public class Update {
    public static  void main(String[] args) throws ClassNotFoundException, SQLException {
        Connection connection = SqlConnection.getCon();
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入要修改的id：");
        int id = scanner.nextInt();
        System.out.println("请输入要修改的姓名：");
        String username = scanner.next();
        String  sql = "update user set username = ? where id = ?";
        PreparedStatement preparedStatement = connection.prepareStatement(sql);
        preparedStatement.setString(1,username);
        preparedStatement.setInt(2,id);
        int i = preparedStatement.executeUpdate();
        if (i>0){
            System.out.println("修改成功");
        }
        else {
            System.out.println("修改失败");
        }
scanner.close();
        connection.close();
        preparedStatement.close();
    }

}
